package com.nbgroup.controller;

import com.nbgroup.pojo.common.PageBean;
import com.nbgroup.pojo.common.PageResult;
import com.nbgroup.pojo.common.Result;
import com.nbgroup.pojo.dto.*;
import com.nbgroup.pojo.vo.*;
import com.nbgroup.service.StatementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.util.List;

@RestController
@Api(tags = "报表相关接口")
@RequestMapping("/report")
@Slf4j
public class StatementController {
    @Autowired
    private StatementService statementService;

    @GetMapping("/contractStatistics/{begin}/{end}")
    @ApiOperation("新增客户")
    public ClientStatementVo clientStatement(@PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
                                             @PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end) {
        return statementService.clientStatement(begin, end);
    }

    @GetMapping("/salesStatistics/{begin}/{end}")
    @ApiOperation("销售统计")
    public ClientStatementVo salesStatistics(@PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
                                             @PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end) {
        return statementService.salesStatistics(begin, end);
    }

    /**
     * 部门渠道统计
     */
    @GetMapping("/deptStatisticsList/{begin}/{end}")
    public PageResult deptStatisticsList(DeptListDto dto,
                                         @PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
                                         @PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end) {
        PageResult pageResult = statementService.queryCon(dto, begin, end);
        return pageResult;
    }

    /***
     * 渠道统计
     * @param begin
     * @param end
     * @return
     */
    @GetMapping("/channelStatisticsList/{begin}/{end}")
    public PageResult channelStatisticsList(DeptListDto dto,
                                            @PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
                                            @PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end) {
        PageResult pageResult = statementService.queryChan(dto, begin, end);
        return pageResult;
    }

    /**
     * 归属人
     *
     * @param begin
     * @param end
     * @return
     */
    @GetMapping("/ownerShipStatisticsList/{begin}/{end}")
    public PageResult ownerShipStatisticsList(DeptListDto dto,
                                              @PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
                                              @PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end) {
        PageResult pageResult = statementService.queryPeople(dto, begin, end);
        return pageResult;
    }

    @GetMapping("/cluesStatistics/{begin}/{end}")
    @ApiOperation("线索统计")
    public ClientStatementVo cluesStatistics(@PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
                                             @PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end) {
        return statementService.cluesStatistics(begin, end);
    }

    @GetMapping("/getVulnerabilityMap/{begin}/{end}")
    @ApiOperation("线索转化率")
    public Result getVulnerabilityMap(@PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
                                      @PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end) {
        CluePercentVo cluePercentVo = statementService.getVulnerabilityMap(begin, end);
        return Result.success(cluePercentVo);
    }

    @GetMapping("/chanelStatistics/{begin}/{end}")
    @ApiOperation("渠道统计")
    public Result chanelStatistics(@PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
                                   @PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end) {
        List<ChanelStatisticsVo> list = statementService.chanelStatistics(begin, end);
        return Result.success(list);
    }

    @GetMapping("/activityStatistics/{begin}/{end}")
    @ApiOperation("活动统计")
    public Result activityStatistics(@PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
                                     @PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end) {
        List<ActivityStatisticsVo> list = statementService.activityStatistics(begin, end);
        return Result.success(list);
    }

    @GetMapping("/subjectStatistics/{begin}/{end}")
    @ApiOperation("学科统计")
    public Result subjectStatistics(@PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
                                    @PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end) {
        List<SubjectStatisticsVo> list = statementService.subjectStatistics(begin, end);
        return Result.success(list);
    }

    @GetMapping("/activityStatisticsList")
    @ApiOperation("活动统计分页查询")
    public PageResult activityStatisticsList(PageActivityStatisticsListDTO pageDto) {
        PageResult pageResult = statementService.activityStatisticsList(pageDto);
        return pageResult;
    }

    @GetMapping("/contractStatisticsList")
    @ApiOperation("客户分页查询")
    public PageBean contractStatisticsList(PageContractStatisticsDTO pageDto) {
        PageBean pageBean = statementService.pageQuery(pageDto);
        return pageBean;
    }

    @GetMapping("/cluesStatisticsList")
    @ApiOperation("查询所有线索")
    public PageBean cluesStatisticsList(PageCluesStatisticsDTO pageDto) {
        return statementService.cluesStatisticsList(pageDto);
    }


}
